<template>
<!--第一步-->
  <div id="app" v-bind:style="appDivStyle">
    <div class="context" ref="context">
      <div class="queryBox" ref="queryBox">
        <el-form :model="formQueryCondition" ref="form" size="mini">
          <!--查询条件-->
          <el-row>
            <el-col :span="5">
              <!-- 剧集编号 -->
              <el-form-item
                :label="$t('assetsAudit.queryLabel.subAssetCode')"
                :label-width="queryformLabelWidth"
              >
                <el-input
                  v-model.trim="formQueryCondition.subassetCode.val"
                  class="queryItemStyle"
                  clearable
                  :placeholder="$t('assetsAudit.queryLabel.placeholderSubAssetCode')"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5" :offset="1">
              <!-- 剧集名称 -->
              <el-form-item
                :label="$t('assetsAudit.queryLabel.subAssetName')"
                :label-width="queryformLabelWidth"
              >
                <el-input
                  v-model.trim="formQueryCondition.subassetName.val"
                  class="queryItemStyle"
                  clearable
                  :placeholder="$t('assetsAudit.queryLabel.placeholderSubAssetName')"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5" :offset="1">
              <!-- 资产编号 -->
              <el-form-item
                :label="$t('assetsAudit.queryLabel.assetCode')"
                :label-width="queryformLabelWidth"
              >
                <el-input
                  v-model.trim="formQueryCondition.assetId.val"
                  class="queryItemStyle"
                  clearable
                  :placeholder="$t('assetsAudit.queryLabel.placeholderAssetCode')"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5" :offset="1">
              <!-- 资产名称 -->
              <el-form-item
                :label="$t('assetsAudit.queryLabel.assetName')"
                :label-width="queryformLabelWidth"
              >
                <el-input
                  v-model.trim="formQueryCondition.assetName.val"
                  class="queryItemStyle"
                  clearable
                  :placeholder="$t('assetsAudit.queryLabel.placeholderAssetName')"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <!-- 下发状态 -->
              <el-form-item
                :label="$t('assetsAudit.queryLabel.sendtoState')"
                :label-width="queryformLabelWidth"
              >
                <el-select v-model="formQueryCondition.sendtoState.val" class="queryItemStyle">
                  <el-option :label="$t('assetsCn.label.all')" value></el-option>
                  <el-option :value="drug.valueCode" :key="drug.valueCode" :label="drug.valueText"
                                    v-for="drug in Sharpness"></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5" :offset="1">
              <!-- 审核状态 -->
              <el-form-item
                :label="$t('assetsCn.queryLabel.assets.isStatus')"
                :label-width="queryformLabelWidth"
              >
                <el-select v-model="formQueryCondition.approvalStatus.val" class="queryItemStyle">
                  <el-option :label="$t('assetsCn.label.all')" value></el-option>
                  <el-option :value="drug.valueCode" :key="drug.valueCode" :label="drug.valueText"
                                    v-for="drug in ApprovalStatus"></el-option>
                  <!-- <el-option :label="$t('assetsCn.queryLabel.assets.pendingReview')" value="PendingReview"></el-option>
                  <el-option :label="$t('assetsCn.label.auditPass')" value="AuditPass"></el-option>
                  <el-option :label="$t('assetsCn.label.auditFailed')" value="AuditFailed"></el-option>
                  <el-option :label="$t('assetsCn.queryLabel.assets.discard')" value="Discard"></el-option> -->
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5" :offset="1">
              <!-- 状态 -->
                <el-form-item :label="$t('AssetsProviderManage.queryLabel.status')"  :label-width="queryformLabelWidth">
                    <el-select v-model="formQueryCondition.isEnable.val" class="queryItemStyle" >
                      <el-option :label="$t('label.all')" value=""></el-option>
                      <el-option :value="drug.valueCode" :key="drug.valueCode" :label="drug.valueText"
                          v-for="drug in enables"></el-option>
                        <!-- <el-option :label="$t('label.all')" value=""></el-option>
                        <el-option :label="$t('label.available')" value="Available"></el-option>
                        <el-option :label="$t('label.invalid')" value="Invalid"></el-option> -->
                    </el-select>
                </el-form-item>
            </el-col>
          </el-row>

          <!-- 按钮 -->
          <el-row>
            <el-col :span="24">
              <div style="text-align:right">
                <!--返回-->
                <!-- <el-form-item v-if="isNeedGoBack">
                    <el-button type="primary" @click="back" icon="el-icon-back">返回</el-button>
                </el-form-item> -->
                <!-- 新增 -->
                <el-form-item>
                  <el-button v-permission="{menuCode: menuCode,resourceCode: 'saveBtnText'}" type="primary" @click="onNew('saveBtnText')">{{ $t('assetsCn.btnText.newBtnText') }}</el-button>
                <!-- </el-form-item> -->
                <!-- 重置 -->
                <!-- <el-form-item> -->
                  <el-button v-permission="{menuCode: menuCode,resourceCode: 'resetBtnText'}" type="primary" @click="onReset('form')">{{ $t('assetsCn.btnText.resetBtnText') }}</el-button>
                <!-- </el-form-item> -->
                <!-- 导入 -->
                <!-- <el-form-item>
                  <el-button v-permission="{menuCode: menuCode,resourceCode: 'ImportBtnText'}" type="primary" @click="openUploadDlg('ImportBtnText')" icon="el-icon-download" :loading="loading" >{{ $t('assetsCn.btnText.importBtnText') }}</el-button>
                </el-form-item> -->
                <!--导入模板下载 -->
                <!-- <el-form-item>
                    <el-button v-permission="{menuCode:menuCode,resourceCode:'downloadTemplate'}"  type="primary" @click="downloadTemplate('downloadTemplate')" icon="el-icon-download" :loading="loading">{{ $t('playManage.btnText.downloadTemplate') }}</el-button>
                </el-form-item> -->
                <!--导出-->
                  <!-- <el-form-item> -->
                    <el-button  v-permission="{menuCode:menuCode,resourceCode:'exportBtnText'}"  type="primary" @click="onExport('exportBtnText')" icon="el-icon-upload2" :loading="loading">{{ $t('shellAssets.btnText.exportBtnText') }}</el-button>
                <!-- </el-form-item> -->
                <!-- 查询 -->
                <!-- <el-form-item> -->
                  <el-button v-permission="{menuCode: menuCode,resourceCode: 'queryBtnText'}" type="primary" @click="onQuery('queryBtnText')" icon="el-icon-search" :loading="loading" >{{ $t('assetsCn.btnText.queryBtnText') }}</el-button>
                </el-form-item>
              </div>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <!-- 列表 -->
      <div class="dataBox" ref="dataBox" >
        <!--第二步  v-if="isInit"-->
        <el-table
          v-if="isInit"
          ref="singleTable"
          :data="tableData"
          :height="tableHeight"
          @sort-change="sortChange"
          v-loading="loading"
          size="mini"
          style="width: 100%;"
          stripe="stripe"
          border="border"
        >
          <!-- 序号 -->
          <el-table-column
            type="index"
            width="50"
            fixed="left"
            :label="$t('assetsCn.table.xh')"
            align="center"
          ></el-table-column>
          <!-- 操作 -->
          <el-table-column :label="$t('assetsCn.table.op')" fixed="left" min-width="290">
            <template slot-scope="scope">
              <el-button v-permission="{menuCode: menuCode,resourceCode: 'editBtnText'}" size="gv" icon="el-icon-edit" :loading="loading" @click="edit(scope.$index, scope.row,'editBtnText')" >
                {{ $t('assetsCn.btnText.editBtnText') }}
              </el-button>
              <el-button v-permission="{menuCode: menuCode,resourceCode: 'detailsBtnText'}" size="gv" icon="el-icon-tickets" :loading="loading" @click="editDetailsCallback(scope.$index, scope.row,'detailsBtnText')" >
                {{ $t('assetsCn.btnText.detailsBtnText') }}
              </el-button>
              <!-- 预览 -->
              <el-button v-permission="{menuCode: menuCode,resourceCode: 'previewBtnText'}" size="gv" icon="el-icon-caret-right" :loading="loading" >
                {{ $t('assetsCn.btnText.preview') }}
              </el-button>
              <el-button v-permission="{menuCode: menuCode,resourceCode: 'passBtnText'}" size="gv" icon="el-icon-delete" type="danger"
                :loading="loading" @click="assetCancellation(scope.$index, scope.row,'passBtnText')"  v-show="scope.row.isEnable=='Available'">
                {{ $t('assetsCn.btnText.logoffBtnText') }}</el-button>
              <el-button size="gv" icon="el-icon-delete" v-show="scope.row.isEnable=='Invalid'" v-permission="{menuCode: menuCode, resourceCode: 'recoveryBtnText'}"
                  type="danger" :loading="loading" @click="recovery(scope.$index, scope.row,'recoveryBtnText')" >{{ $t('btnText.recoveryBtnText') }}</el-button>
            </template>
          </el-table-column>
           <!-- 剧集编号 -->
          <el-table-column
            prop="subassetCode"
            min-width="160"
            fixed="left"
            :label="$t('assetsAudit.table.subAssetCode')"
            sortable="custom"
            sort-by="subassetCode"
          ></el-table-column>
          <!-- 剧集名称 -->
          <el-table-column
            prop="subassetName"
            min-width="160"
            fixed="left"
            :label="$t('assetsAudit.subAssets.subAssetName')"
            sortable="custom"
            sort-by="subassetName"
          ></el-table-column>
          <!-- 集数 -->
          <el-table-column
            :label="$t('assetsCn.table.assets.itemNum')"
            min-width="95"
            sortable="custom"
            prop="subassetNum"
            sort-by="subassetNum"
          ></el-table-column>
          <!-- 资产编号 -->
          <el-table-column
            prop="assetCode"
            min-width="160"
            :label="$t('assetsAudit.assetCode')"
            sortable="custom"
            sort-by="assetCode"
          ></el-table-column>
          <!-- 资产名称 -->
          <el-table-column
            prop="assetName"
            min-width="160"
            :label="$t('assetsAudit.assetName')"
            sortable="custom"
            sort-by="assetName"
          ></el-table-column>
          <!-- 审核状态 -->
          <el-table-column
            :label="$t('assetsCn.table.assets.status')"
            min-width="140"
            sortable="custom"
            prop="approvalStatusName"
            sort-by="approvalStatus"
          ></el-table-column>
          <!-- 下发状态 -->
          <el-table-column
            :label="$t('assetsCn.table.assets.sendtoState')"
            min-width="140"
            sortable="custom"
            prop="sendtoStateName"
            sort-by="sendtoState"
          ></el-table-column>
          <!-- 类型 -->
          <el-table-column
            prop="timeLength"
            min-width="95"
            sortable="custom"
            :label="$t('assetsCn.table.assets.timeLength')"
            sort-by="timeLength"
          ></el-table-column>

          <!-- 清晰度 -->
          <el-table-column
            :label="$t('assetsCn.table.assets.sharpness')"
            min-width="95"
            sortable="custom"
            prop="subassetDefinition"
            sort-by="subassetDefinition"
          ></el-table-column>
          <!-- 更新时间 -->
          <!-- <el-table-column
            :label="$t('assetsCn.table.assets.updateTime')"
            min-width="180"
            sortable="custom"
            prop="lastUpdateTime"
            sort-by="lastUpdateTime"
          ></el-table-column> -->
        </el-table>
      </div>
    </div>
    <div class="pageBox">
      <el-pagination
        @size-change="sizeChange"
        @current-change="currentPageChange"
        :current-page="pager.curPage"
        :page-sizes="pager.sizes"
        :page-size="pager.curSize"
        :background="true"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pager.total"
      ></el-pagination>
    </div>

    <!--编辑对话框-->
    <el-dialog :title="$t('assetsCn.label.dialogTitle')" :visible.sync="isShowEditForm" top="5vh" :close-on-click-modal="false">
      <el-form :model="editForm" ref="editForm" size="mini" :label-position="editFormPosition" status-icon="status-icon" :rules="editRules" >
      <!-- 资产编号 -->

        <el-form-item :label="$t('assetsAudit.assetCode')" :label-width="editformLabelWidth" prop="assetCode" >
          <el-input ref="assetCodeInput" v-model.trim="editForm.assetCode" maxlength="36" :placeholder="$t('assetsAudit.queryLabel.placeholderAssetCode')" @focus="chooseAsset"></el-input>
          <!-- <el-button size="gv" icon="el-icon-tickets" :loading="loading" @click="chooseAsset" >选择资产</el-button> -->
        </el-form-item>
        <!-- 资产名称 -->
        <!-- <el-form-item :label="$t('assetsAudit.assetName')" :label-width="editformLabelWidth" v-show="display" prop="assetName" >
          <el-input v-model.trim="assetName" :disabled="display" maxlength="20" :placeholder="$t('assetsAudit.queryLabel.placeholderAssetName')" ></el-input>
        </el-form-item> -->
      <!-- 剧集编号 -->
        <!-- <el-form-item
          v-show="isShow"
          :label="$t('assetsAudit.queryLabel.subAssetCode')"
          :label-width="editformLabelWidth"
          prop="subassetCode"
        >
          <el-input
            v-model.trim="editForm.subassetCode"
            maxlength="20"
            :disabled="canEditCode"
            :placeholder="$t('assetsAudit.queryLabel.placeholderSubAssetCode')"
          ></el-input>
        </el-form-item> -->
        <!-- 剧集名称 -->
        <el-form-item
          :label="$t('assetsAudit.queryLabel.subAssetName')"
          :label-width="editformLabelWidth"
          prop="subassetName"
        >
          <el-input
            v-model.trim="editForm.subassetName"
            maxlength="50"
            :placeholder="$t('assetsAudit.queryLabel.placeholderSubAssetName')"
          ></el-input>
        </el-form-item>
        <!-- 集数 -->
        <el-form-item
          :label="$t('assetsCn.editLabel.assets.itemNum')"
          :label-width="editformLabelWidth"
          prop="subassetNum"
        >
          <el-input
            v-model.trim="editForm.subassetNum"
            maxlength="8"
            :placeholder="$t('assetsCn.editLabel.assets.placeholderEpisode')"
          ></el-input>
        </el-form-item>
        <!-- 清晰度 -->
        <el-form-item
          :label="$t('assetsCn.editLabel.assets.definition')"
          :label-width="editformLabelWidth"
          prop="subassetDefinition"
        >
          <el-select v-model.trim="editForm.subassetDefinition" maxlength="50">
            <!-- <el-option :label="$t('assetsCn.label.all')" value></el-option> -->
            <el-option :value="drug.valueCode" :key="drug.valueCode" :label="drug.valueText"
                                v-for="drug in Sharpness"></el-option>
          </el-select>
        </el-form-item>
        <!-- 绝对播放地址 -->
        <el-form-item
          :label="$t('assetsCn.editLabel.assets.absoluteAddress')"
          :label-width="editformLabelWidth"
          prop="absoluteUrl"
        >
          <el-input
            v-model.trim="editForm.absoluteUrl"
            maxlength="500"
            :placeholder="$t('assetsCn.editLabel.assets.placeholderAbsoluteAddress')"
          ></el-input>
        </el-form-item>
        <!-- 时长 -->
        <el-form-item
          :label="$t('assetsCn.editLabel.assets.timeLength')"
          :label-width="editformLabelWidth"
          prop="timeLength"
        >
          <el-input
            v-model.trim="editForm.timeLength"
            maxlength="50"
            :placeholder="$t('assetsCn.editLabel.assets.placeholderTimeLength')"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button
          size="mini"
          @click="isShowEditForm = false"
          :loading="loading"
        >{{ $t('assetsCn.btnText.cancelBtnText') }}</el-button>
        <el-button
          size="mini"
          type="primary"
          @click="submitForm('editForm',currentResCode)"
          :loading="loading"
        >{{ $t('assetsCn.btnText.saveBtnText') }}</el-button>
      </div>
    </el-dialog>

    <!--详情框-->
    <el-dialog :title="$t('assetsCn.label.dialogTitle')" :visible.sync="isShowDetails" top="5vh" width="60%" :close-on-click-modal="false">
      <el-row class="datarow">
        <el-col class="datacol titlecol" :span="titleSpan">{{ $t('基本信息') }}</el-col>
      </el-row>
      <el-row class="datarow bgrow">
      <!-- 壳资产编号，壳资产名称 -->
            <el-col class="labcol" :span="labelSpan">{{ $t('assetsAudit.table.assetCode') + ":"  }}</el-col>
            <el-col class="datacol" :span="dataSpan">{{ editDetailsForm.assetEntity.assetCode }}</el-col>
            <el-col class="labcol" :span="labelSpan">{{ $t('assetsAudit.table.assetName') + ":"  }}</el-col>
            <el-col class="datacol" :span="dataSpan">{{ editDetailsForm.assetEntity.assetName }}</el-col>
      </el-row>
        <!-- <el-form-item
          :label="$t('assetsCn.editLabel.assets.shellCode')"
          :label-width="editformLabelWidth"
          prop="shellCode"
        >
         <el-input
            v-model.trim="editDetailsForm.shellCode"
            maxlength="20"
            :disabled="true"
          ></el-input>
        </el-form-item> -->
        <!-- 壳资产名称 -->
        <!-- <el-form-item
          :label="$t('assetsCn.editLabel.assets.shellName')"
          :label-width="editformLabelWidth"
          prop="shellName"
        >
          <el-input
            v-model.trim="editDetailsForm.shellName"
            maxlength="20"
            :disabled="true"
          ></el-input>
        </el-form-item> -->

      <!-- 子资产编号，子资产名称-->
      <el-row class="datarow">
        <el-col class="labcol" :span="labelSpan">{{ $t('assetsAudit.table.subAssetCode') + ":"  }}</el-col>
        <el-col class="datacol" :span="dataSpan">{{ editDetailsForm.subassetCode }}</el-col>
        <el-col class="labcol" :span="labelSpan">{{ $t('assetsAudit.table.subAssetName') + ":"  }}</el-col>
        <el-col class="datacol" :span="dataSpan">{{ editDetailsForm.subassetName }}</el-col>
      </el-row>
        <!-- 类型，集数 -->
      <el-row class="datarow bgrow">
        <el-col class="labcol" :span="labelSpan">{{ $t('assetsAudit.subAssetsInfo.type') + ":"  }}</el-col>
        <el-col class="datacol" :span="dataSpan">{{ editDetailsForm.assetEntity.assetType }}</el-col>
        <el-col class="labcol" :span="labelSpan">{{ $t('assetsAudit.subAssetsInfo.itemNum') + ":"  }}</el-col>
        <el-col class="datacol" :span="dataSpan">{{ editDetailsForm.subassetNum }}</el-col>
      </el-row>
        <!-- 状态，清晰度-->
        <el-row class="datarow">
          <el-col class="labcol" :span="labelSpan">{{ $t('assetsAudit.subAssetsInfo.status') + ":"  }}</el-col>
          <el-col class="datacol" :span="dataSpan">{{ editDetailsForm.approvalStatus }}</el-col>
          <el-col class="labcol" :span="labelSpan">{{ $t('assetsAudit.subAssetsInfo.definition') + ":"  }}</el-col>
          <el-col class="datacol" :span="dataSpan">{{ editDetailsForm.subassetDefinition }}</el-col>
        </el-row>
        <!-- 创建时间 -->
        <el-row class="datarow bgrow">
          <el-col class="labcol" :span="labelSpan">{{ $t('assetsAudit.subAssetsInfo.createTime') + ":"  }}</el-col>
          <el-col class="datacol" :span="dataSpan">{{ editDetailsForm.createdDate }}</el-col>
        </el-row>
          <!-- 简介 -->
          <!-- <el-row class="datarow">
          <el-col class="labcol" :span="labelSpan">{{ $t('assetsAudit.subAssetsInfo.introduction') + ":"  }}</el-col>
          <el-col class="datacol" :span="dataSpan">{{ editDetailsForm.introduction }}</el-col>
        </el-row> -->
        <!-- 绝对地址 -->
          <el-row class="datarow">
          <el-col class="labcol" :span="labelSpan">{{ $t('assetsAudit.subAssetsInfo.absoluteURL') + ":"  }}</el-col>
          <el-col class="datacol" :span="dataSpan">{{ editDetailsForm.absoluteUrl }}</el-col>
        </el-row>
      <!-- <div slot="footer">
        <el-button
          size="mini"
          @click="isShowEditForm = false"
          :loading="loading"
        >{{ $t('btnText.cancelBtnText') }}</el-button>
        <el-button
          size="mini"
          type="primary"
          @click="submitForm('editForm')"
          :loading="loading"
        >{{ $t('btnText.saveBtnText') }}</el-button>
      </div> -->
    </el-dialog>
    <!--资产选择框-->
    <el-dialog :title="$t('label.dialogDetails')" :visible.sync="isShowChoose" top="5vh" width="60%" :close-on-click-modal="false">
        <!-- <el-tabs v-model="ChooseName" type="border-card">
              <assets-choose ref="AssetsChoose" v-on:ShellAssets="LinkToAsset" :datas="isShowChoose"></assets-choose>
        </el-tabs> -->
        <assets-choose ref="AssetsChoose" v-on:ShellAssets="LinkToAsset"></assets-choose>
    </el-dialog>
    <!-- 导入 -->
    <el-dialog title="导入" width="400px" :visible.sync="dlgUploadVisible" :close-on-click-modal="false">
        <upload-file
            v-bind:uploadUrl="uploadCourseMaterialUrl"
            v-bind:acceptFileType="'.xlsx'"
            v-bind:uploadParams="uploadCourseMaterialParams"
            v-bind:fileList="fileList"
            v-bind:autoUpload="false"
            v-bind:fileLimit="1"
            v-bind:selectName="'选取文件'"
            v-bind:uploadBtn="'提交'"
            v-bind:fileTypeText="'xlsx'"
            v-bind:submitSuccess="submitUploadSuccess"
        ></upload-file>
    </el-dialog>

  </div>
</template>

<script>
import comBaseVue from "../../baseViewModel";
import AssetsChoose from './AssetsChoose';

export default {
  mixins: [comBaseVue],
  name: "AssetsManage",
  props: {
    isNeedGoBack:Boolean,
    curRootAssets: Object,
    menuCode: String
  },
  data() {
    return {
      //第三步
        isInit:false,
        // display:true,
        ChooseName:'one',
        fileList: [],
        Sharpness:[],
        isShowChoose:false,
        Character: null,
        tableChecked: [],
        ApprovalStatus:[],
        enables: [],
        tableHeight:200,
        //编辑布局
        //标题
        titleSpan:24,
        labelSpan:3,
        dataSpan:9,
      // tableHeight: this.$store.getters.appHeightNum - 176 + 33,
        appDivStyle:{
            height:this.$store.getters.appHeight,
        },
      modelName: "com.ispr.iptv.entity.media.SubAssetEntity",
      modelName2: "com.ispr.iptv.entity.media.VSubassetEntity",
      // 查询条件
      formQueryCondition: {
        assetId: {
          //mapName: 'code',  映射的别名 在同时查询一个属性时需要别名
          //gName:'code',   组名
          // key: "assetEntity.assetCode",
          key: "assetCode",
          op: "LIKE", // 操作符
          val: "" // 查询的值
        },
        assetName: {
          // key: "assetEntity.assetName",
          key: "assetName",
          op: "LIKE", // 操作符
          val: "" // 查询的值
        },
        subassetCode: {
          key: "subassetCode",
           op: "LIKE", // 操作符
          val: ""
        },
        subassetName: {
          key: "subassetName",
           op: "LIKE", // 操作符
          val: ""
        },
        sendtoState: {
          key: "sendtoState",
          op: "=", // 操作符
          val: ""
        },
        approvalStatus: {
          key: "approvalStatus",
          op: "=", // 操作符
          val: ""
        },
        isEnable: {
          key: "isEnable",
          op: "=", // 操作符
          val: ""
        },
      },

      // 排序对象
      sort: {
          key: "subassetNum",
          dir: "Desc"
      },

      // 编辑面板绑定的对象
      editForm: {
        keyId: 0,
        version: 0,
        assetCode: "",
        //assetName: "",
        assetId:"",
        subassetCode: "",
        subassetName: "",
        subassetNum: "",
        subassetDefinition: "",
        absoluteUrl: "",
        approvalStatus: "",
        sendtoState: "",
        timeLength:"",
      },

      assetName:"",
      // 编辑面板的验证规则
      editRules: {
        assetCode: [
          {
            required: true,
            message: this.$i18n.t("assetsAudit.rules.assetCode"),
            trigger: "blur"
          }
        ],
        // assetName: [
        //   {
        //     required: true,
        //     message: this.$i18n.t("assetsAudit.rules.assetName"),
        //     trigger: "blur"
        //   }
        // ],
        subassetCode: [
          {
            required: true,
            message: this.$i18n.t("assetsCn.rules.assets.subAssetCode"),
            trigger: "blur"
          }
        ],
        subassetName: [
          {
            required: true,
            message: this.$i18n.t("assetsCn.rules.assets.subAssetName"),
            trigger: "blur"
          }
        ],
        // association: [
        //   {
        //     required: true,
        //     message: this.$i18n.t("assetsCn.rules.assets.association"),
        //     trigger: "blur"
        //   }
        // ],
        subassetNum: [
          {
            required: true,
            message: this.$i18n.t("assetsCn.rules.assets.itemNum"),
            trigger: "blur"
          }
        ],
        timeLength: [
          {
            required: true,
            message: this.$i18n.t("assetsCn.rules.assets.timeLength"),
            trigger: "blur"
          }
        ]
      },
      UpdateOrSave:"",//请求地址
    //   详情框是否显示
        isShowDetails: false,
        isShow: true,
    //   声明详情框
        editDetailsForm:{assetEntity:""},

       //////////////////////////////////文件导入/////////////////////
        uploadCourseMaterialUrl: '/api/import/upload',
        uploadCourseMaterialParams: null,
        dlgUploadVisible: false


    };
  },
  methods: {
    // 查询按钮
        onQuery: function(rescode) {
            this.currentResCode = (rescode && rescode!=='') ? rescode : '';
            this.pager.curPage = 1;
            this.queryTable();
        },
        // 查询网格数据
        queryTable: function() {
            this.loading = true;
            this.queryModel(this.modelName2,"Query",this.formQueryCondition,this.pager,this.sort,this.setTableData)
        },// 查询网格数据成功后的回调
        setTableData: function(isSuccess,json) {
            this.currentResCode = '';
            this.loading = false;
            try{
                if (isSuccess) {
                    //alert(JSON.stringify(json));
                    this.pager.total = json.total;
                    this.tableData = [];
                    for (var i = 0; i < json.list.length; i++) {
                        this.tableData.push(json.list[i]);
                    }

                }
                else {
                    this.$message.error(json.msg);
                }
            }
            catch(e){
                alert(e);
            }
        },
    // 新增
    onNew: function(rescode) {
       this.currentResCode = (rescode && rescode!=='') ? rescode : '';
      // this.display = false;
      this.isShowEditForm = true;
      if (this.$refs["editForm"]) {
        this.$refs["editForm"].resetFields();
      }
      this.editForm.keyId = "";
      this.editForm.version = "";
      // this.editForm.shellCode = "";
      // this.editForm.shellName = "";
      this.editForm.assetId = "";
      this.editForm.assetCode = "";
      this.assetName = "";
      // this.editForm.subassetCode = "";
      this.editForm.subassetName = "";
      this.editForm.subassetNum = "";
      this.editForm.subassetDefinition = "";
      this.editForm.absoluteUrl = "";
      this.editForm.timeLength = "";
      this.editForm.approvalStatus = "PendingReview";
      this.editForm.isEnable = "Available";
      this.editForm.sendtoState = "StayDown";
      // this.editForm.isEnabled = "Available";
      // this.isShow = false;
      this.UpdateOrSave = "/api/subAsset/save";
      this.canEditCode = false;

    },

    // 提交编辑面板数据
    submitForm: function (formName) {
        var _this = this;
        //this.setEditFormCheck();
        this.$refs[formName].validate(function (valid) {
            if (valid) {
                _this.loading = true;
                _this.procControllerSave(
                    _this.curCommand,
                    _this.modelName,
                    "Default",
                    _this.editForm,
                    _this.submitFormCallbackSave);
            } else {
                return false;
            }
        });
    },
    procControllerSave: function(commandCode, className, commandArgs, commandBody,callback) {
        var requestArgs = {
            commandCode: commandCode,
            className: className,
            commandArgs: commandArgs,
            commandBody: commandBody,
            userInfo: this.getUserInfo()
        };
        if (this.isExistResourceCode(this)) {
            this.headersObj['X-AOHO-Resource'] = this.menuCode + ',' + this.currentResCode;
        }
        this.axios.post(this.UpdateOrSave,
                requestArgs, {headers: this.headersObj})
            .then(function(res) {
                if (res.data.code == "SUCCESS") {
                    callback.call(this, true, res.data.data);
                } else {
                    callback.call(this, false, res.data);
                }
            })
            .catch(function(error) {
                console.log(error);
                callback.call(this, false, "serverError");
            });
    },

    // 执行命令后的回调函数
    submitFormCallbackSave: function submitFormCallbackSave(isSuccess,json) {
        this.loading = false;
        if(isSuccess){
            this.isShowEditForm = false;
            this.$message({
                message: this.$i18n.t("message.successTip"),//resource.message.successTip,
                type: 'success'
            });
            this.queryTable();
        }
        else
        {
            this.$message({
                            message: json.msg,
                            type: 'warning'
                            });
        }
    },

    // 重置
    onReset: function() {
      if (this.$refs["form"]) {
        this.$refs["form"].resetFields();
      }

      this.formQueryCondition.assetId.val = "";
      this.formQueryCondition.assetName.val = "";
      this.formQueryCondition.subassetCode.val = "";
      this.formQueryCondition.subassetName.val = "";
      this.formQueryCondition.subassetDefinition.val = "";
      this.formQueryCondition.approvalStatus.val = "";
      this.formQueryCondition.isEnable.val = "Available";
    },
      /////下载导入模板
    downloadTemplate: function downloadTemplate (rescode) {
       this.currentResCode = (rescode && rescode!=='') ? rescode : '';
      this.downloadByIdOrName(this, '/import/downtemplate', 'fileName', '资产管理导入模板.xlsx', '资产管理导入模板.xlsx');
    },
/////////////////////////////////// 资产导入 ///////////////////////////////////////////
   // 导出
    onExport: function(rescode){
       this.currentResCode = (rescode && rescode!=='') ? rescode : '';
        let param = {
          'className': 'com.ispr.iptv.entity.media.SubAssetEntity',
          'opKey': 'Export',
          'params':this.queryObjToArray(this.formQueryCondition),
          'sort': [{ 'col': 'createdDate', 'order': 'desc' }],
          'fileName': '剧集管理'
        };
        let fileName = '剧集管理' + '.xlsx';
        this.downloadByIdOrName(this, '/file/export', 'param', JSON.stringify(param), fileName);
      },
    // 打开导入资材关系的dialog
    openUploadDlg: function openUploadDlg (rescode) {
       this.currentResCode = (rescode && rescode!=='') ? rescode : '';
      let _this = this;
      this.$alert('注意：导入后将会覆盖原有的所有数据，是否继续？', '提示', {
        confirmButtonText: '确定',
        callback: action => {
          if (action === 'confirm') {
            // 初始化错误文件下载id
            _this.errorTaskId = null;
            // 清空文件列表
            _this.fileList = [];
            _this.dlgUploadVisible = true;
            // this.uploadPhorderUrl = this.baseUrl+'/import/upload';
            _this.uploadCourseMaterialParams = {'className': _this.modelName};
          }
        }
      });
    },

    submitUploadSuccess: function submitUploadSuccess (response, file, fileList) {
      if (response.code === 'SUCCESS') {
        if (response.data.status === '0') {
          this.dlgUploadVisible = false;
          this.$message.success('导入成功');
          this.fileList = []; // 清空上传文件列表
          // 刷新表格数据
          this.onQuery();
          return false;
        }
        if (response.data.status === '3') {
          let _this = this;
          this.$alert('导入失败，是否下载失败原因文件?', '提示', {
            confirmButtonText: '确定',
            callback: function callback (action) {
              if (action === 'confirm') {
                _this.downloadByIdOrName(_this, '/import/downerr', 'taskId', response.data.taskId, response.data.errFileName);
              } else {
                _this.$message({
                  type: 'info',
                  message: '已取消'
                });
              }
            }
          });
          this.fileList = []; // 清空上传文件列表
          this.dlgUploadVisible = false;
        }
      } else {
        this.$message.error(response.msg);
      }
    },
//////////////////////////////////////////////////////////////////////////////////////////////////

    // 授权按钮单击事件
    editMenu: function(index, row) {},

     // 编辑按钮单击事件
    edit: function(index, row,rescode) {
      this.currentResCode = (rescode && rescode!=='') ? rescode : '';

      // this.display=true;
      //dataAccess.queryDomainModelByKeyID(this, modelName, "Query", row.keyID, true, this.$options.methods.editCallback);
      this.queryModelByKeyID(
        this.modelName,
        row.keyId,
        "ById",
        this.editCallback
      );
    },
    // 编辑按钮回调事件
    editCallback: function(isSuccess, json) {
      if (isSuccess) {
        this.UpdateOrSave = "/api/subAsset/update";
        this.isShowEditForm = true;
        if (this.$refs["editForm"]) {
          this.$refs["editForm"].resetFields();
        }
        this.editForm.keyId = json.keyId;
        this.editForm.version = json.version,
        this.editForm.assetCode = json.assetEntity.assetCode,
        this.editForm.assetId = json.assetId,
        this.assetName = json.assetEntity.assetName;
        this.editForm.subassetCode = json.subassetCode;
        this.editForm.subassetName = json.subassetName;
        this.editForm.subassetNum = json.subassetNum;
        this.editForm.subassetDefinition = json.subassetDefinition;
        this.editForm.absoluteUrl = json.absoluteUrl;
        this.editForm.timeLength = json.timeLength;
        this.editForm.approvalStatus = "PendingReview";
        this.editForm.sendtoState = "StayDown";
        this.isShow = true;
        // this.canEditCode = true;
      } else {
        this.$message({
          message: json.msg,
          type: "warning"
        });
      }
    },

        // 执行命令后的回调函数
        submitFormCallback: function submitFormCallback(isSuccess,json) {
            this.loading = false;
            if(isSuccess){
                this.isShowEditForm = false;
                this.$message({
                    message: this.$i18n.t("message.successTip"),//resource.message.successTip,
                    type: 'success'
                });
                this.queryTable();
            }
            else
            {
                this.$message({
                                message: json.msg,
                                type: 'warning'
                                });
            }
        },
    //编辑面板提交后调用，设置唯一性验证条件
    setEditFormCheck:function setEditFormCheck(){
        if(this.curCommand == "SaveNew"){
            this.editFormCheck = [{
                    key: 'assetId',
                    op: '=', // 操作符
                    val: this.editForm.assetId// 查询的值
                },{
                    key: 'isEnable',
                    op: '=', // 操作符
                    val: 'Available'
                }];
        }else if(this.curCommand == "PartialUpdateProc"){
            this.editFormCheck = [{
                    key: 'assetId',
                    op: '=', // 操作符
                    val: this.editForm.assetId// 查询的值
                },{
                    key: 'isEnable',
                    op: '=', // 操作符
                    val: 'Available'
                },{
                    key: 'keyId',
                    op: '<>', // 操作符
                    val: this.editForm.keyId
                }];
        }

    },
    // 详情按钮点击事件
    editDetailsCallback: function(index, row,rescode) {
      this.currentResCode = (rescode && rescode!=='') ? rescode : '';
            this.queryModelByKeyID(this.modelName,row.keyId,"Query",this.editDetails);
        },
    //详情时回调事件
    editDetails: function(isSuccess, json) {
        this.isShowDetails = true;
        this.editDetailsForm = json;

        this.canEditCode = true;
    },
    //选择编剧单击事件
    chooseAsset: function(){
      this.isShowChoose = true;
      this.$refs.AssetsChoose.tableChecked = [];
      this.$refs.AssetsChoose.onReset();
      this.$refs.AssetsChoose.onQuery();
    },
    LinkToAsset: function(data, isShowChoose){
        // console.info(data);
        // this.isShowChoose = isShowChoose;
        this.editForm.assetId = data.assetId;
        this.editForm.assetCode = data.assetCode;
        // this.$refs.assetCodeInput.focus();
        // this.$refs.assetCodeInput.blur();
        if(this.$refs['editForm']) {
          this.$refs['editForm'].clearValidate();
        }
        this.isShowChoose = false;
    },
    // 剧集注销按钮
        assetCancellation: function(index, row, rescode) {
          
            this.currentResCode = (rescode && rescode!=='') ? rescode : '';
            var _this = this;
            this.$confirm(this.$i18n.t("message.confirmlogoffMessage"),
                this.$i18n.t("message.confirmTitle"), {
                confirmButtonText: this.$i18n.t("message.yes"),
                cancelButtonText: this.$i18n.t("message.cancel"),
                type: "warning",
                callback: function (action, instance) {
                    if (action == "confirm") {
                      
                        var commandBody = {  "keyId": row.keyId,"assetId":row.assetId, "version": row.version, isEnable: "Invalid" };
                        // var commandBody = {
                        //     data: [{ keyID: row.keyID, ver: row.version }],
                        //     val: "Invalid",
                        //     count: 1
                        // };
                        _this.loading = true;
                        _this.procCommand("assetCancellationProc",//"ChangeIsEnabledState",
                                _this.modelName,
                                "N",
                                commandBody,
                                null,
                                _this.submitFormCallback);
                    }
                    
                }
            });
        },
    //恢复按钮
    recovery: function(index, row,rescode) {
        this.currentResCode = (rescode && rescode!=='') ? rescode : '';
        var _this = this;
        this.$confirm(this.$i18n.t("message.confirmRevertLogoffMessage"),
            this.$i18n.t("message.confirmTitle"), {
            confirmButtonText: this.$i18n.t("message.yes"),
            cancelButtonText: this.$i18n.t("message.cancel"),
            type: "warning",
            callback: function (action, instance) {
                if (action == "confirm") {
                    var commandBody = {  "keyId": row.keyId,"assetId":row.assetId, "version": row.version, isEnable: "Available" };
                    _this.loading = true;
                    _this.procCommand("assetCancellationRecoveryProc",
                            _this.modelName,
                            "default",
                            commandBody,
                            null,
                            _this.submitFormCallback);
                }

            }
        });
    },
    //回退事件
    back: function(isSuccess, json) {
        //this.$router.go(-1);//后退
        this.$parent.setCurrentComponent("goBack",null);
    },
    // 为下发状态下拉框赋值
    findSharpness: function() {
        this.findByTypeCode("10011",this.setSharpness)
    },
    // 查询下发状态下拉框数据成功后的回调
    setSharpness: function(isSuccess,json) {
        try{
            if (isSuccess) {
                this.Sharpness = [];
                for (var i = 0; i < json.data.length; i++) {
                    this.Sharpness.push(json.data[i]);
                }
            }
            else {
                this.$message.error(json.msg);
            }
        }
        catch(e){
            alert(e);
        }
    },
    // 为审核状态下拉框赋值
    findApprovalStatus: function() {
        this.findByTypeCode("10007",this.setApprovalStatus)
    },
    // 查询清晰度下拉框数据成功后的回调
    setApprovalStatus: function(isSuccess,json) {
        try{
            if (isSuccess) {
                this.ApprovalStatus = [];
                for (var i = 0; i < json.data.length; i++) {
                    this.ApprovalStatus.push(json.data[i]);
                }
            }
            else {
                this.$message.error(json.msg);
            }
        }
        catch(e){
            alert(e);
        }
    },
    // 为状态下拉框赋值
    findEnables: function() {
        this.findByTypeCode("10001",this.setEnables)
    },
    // 查询状态下拉框数据成功后的回调
    setEnables: function(isSuccess,json) {
        try{
            if (isSuccess) {
                this.enables = [];
                for (var i = 0; i < json.data.length; i++) {
                    this.enables.push(json.data[i]);
                }
            }
            else {
                this.$message.error(json.msg);
            }
        }
        catch(e){
            alert(e);
        }
    },
    //定时方法，刷新高度------第五步
    initTable:function(){
    //alert("setTimeout");
    this.tableHeight = this.$refs.context.offsetHeight - this.$refs.queryBox.offsetHeight;
    this.isInit = true;
    },
    enterDown(){
      var g = this
      
      if(g.isShowEditForm){
        g.submitForm('editForm',g.currentResCode)
      }else if(g.isShowChoose){
        // g.$refs.AssetsChoose.submitForm('editForm',g.currentResCode)
      }else if(!g.loading){
        g.onQuery()
      }
    }
  },

  mounted: function mounted() {
    this.formQueryCondition.isEnable.val = "Available";
    this.findSharpness(),
    this.findApprovalStatus();
    this.findEnables();
    this.onQuery();
    //第六步
      window.setTimeout(this.initTable,100);
    //alert(this.isNeedGoBack);
    //alert(this.curRootAssets);
    //this.formQueryCondition.shellCode.val = this.$route.params.code;
    //this.formQueryCondition.shellName.val = this.$route.params.name;

  },
  components: {
    "assets-choose": AssetsChoose,
    'upload-file': () => import('../common/UploadFile'),
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->

<style scoped>
.main{
    height: 100%;
    width: 100%;
    font-size: 14px;
    color: #333333;
    font-family:"Microsoft YaHei";

}
.datarow {
    border: 1px solid #eeeeee;
    padding: 0px 0px 0px 0px;
    margin-bottom: 0px;
    &:last-child {
      margin-bottom: 0;
    }
  }

.titlecol{
    font-weight: bold;
}

.labcol {
  padding: 3px 3px 3px 5px;
  border-radius: 4px;
  font-size: 14px;
  text-align:right;
  border-right: 1px solid #eeeeee;
}

.datacol {
  padding: 3px 3px 3px 3px;
  border-radius: 0px;
  text-align:left;

vertical-align: middle;
  border-right: 1px solid #eeeeee;
}

.bgrow{
    background-color: #d4f1ff;
}
</style>
